Writing the Latex File

The second pass (invoked via a call to write_tex) copies most of the text from the source file straight into a .tex file. Definitions are formatted slightly and cross-reference information is printed out.

Note that all the formatting is handled in this section. If you don't like the format of definitions or indices or whatever, it'll be in this section somewhere. Similarly, if someone wanted to modify nuweb to work with a different typesetting system, this would be the place to look.

@d Function... @extern void write_tex(); @

We need a few local function declarations before we get into the body of write_tex.

@o latex.c @static void copy_scrap(); /* formats the body of a scrap */ static void print_scrap_numbers(); /* formats a list of scrap numbers */ static void format_entry(); /* formats an index entry */ static void format_user_entry(); @

The routine write_tex takes two file names as parameters: the name of the web source file and the name of the .tex output file. @o latex.c @void write_tex(file_name, tex_name) char *file_name; char *tex_name; FILE *tex_file = fopen(tex_name, "w"); if (tex_file) if (verbose_flag) fprintf(stderr, "writing source_open(file_name); @<Copy source_file into tex_file@> fclose(tex_file); else fprintf(stderr, " @| write_tex @

We make our second (and final) pass through the source web, this time copying characters straight into the .tex file. However, we keep an eye peeled for @@ characters, which signal a command sequence.

@d Copy source_file... @ int scraps = 1; int c = source_get(); while (c != EOF) if (c == '@@') @<Interpret at-sequence@> else putc(c, tex_file); c = source_get(); @

@d Interpret at-sequence @ int big_definition = FALSE; c = source_get(); switch (c) case 'O': big_definition = TRUE; case 'o': @<Write output file definition@> break; case 'D': big_definition = TRUE; case 'd': @<Write macro definition@> break; case 'f': @<Write index of file names@> break; case 'm': @<Write index of macro names@> break; case 'u': @<Write index of user-specified names@> break; case '@@': putc(c, tex_file); default: c = source_get(); break; @



Subsections